package priv.stones.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;

/**
 * @Author: Stones
 * @Description:
 * @Date: 2017/9/27 11:21
 */
public class Jdbc3 {


    public static void main(String[] args) throws SQLException {
        Connection cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/spider1?serverTimezone=UTC&characterEncoding=utf8&useSSL=true&useUnicode=true",
                "root", "Hujinyang1");


        String sql = "insert into test(name,age) VALUES (?,?);";
        PreparedStatement preparedStatement = cn.prepareStatement(sql);
        cn.setAutoCommit(false);

        preparedStatement.setString(1, "hu' or 'lei1");
        preparedStatement.setInt(2, 2220);
        preparedStatement.addBatch();

        preparedStatement.setString(1, "123");
        preparedStatement.setInt(2, 123);
        preparedStatement.addBatch();

        int[] result1 = preparedStatement.executeBatch();
        System.out.println(Arrays.toString(result1));

        cn.commit();

//        cn.setAutoCommit(true);

        cn.close();

    }

}
